package com.bk.game.cat;

import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.utils.Disposable;
import com.bk.game.global.BkGlobal;
import com.bk.game.screen.GameScreen;

/**
 * 描述:全力
 * 
 * @author linqiang(866116)
 * @Since 2012-9-6
 */
public class BoomBtn extends Actor implements Disposable {
	private Sprite sprite, outSprite;
	private float scaleX, scaleY;
	private float ax, ay;
	private boolean boom;

	public BoomBtn(TextureRegion region, float left, float top) {
		sprite = new Sprite(region);
		scaleX = 268 * BkGlobal.factorx;
		scaleY = 66 * BkGlobal.factory;
		sprite.setSize(scaleX, scaleY);
		this.ax = left * BkGlobal.factorx;
		this.ay = top * BkGlobal.factory;
		sprite.setPosition(this.ax, this.ay);
		outSprite = new Sprite(sprite);
		boom = false;
		outSprite.setColor(0.2f, 0.2f, 0.2f, 0.8f);
	}

	@Override
	public void dispose() {
	}

	@Override
	public void draw(SpriteBatch spriteBatch, float arg1) {
		sprite.draw(spriteBatch);
		outSprite.draw(spriteBatch);
		if (!boom && GameScreen.singlePressTime != 0 && GameScreen.singlePressTime % 10 == 0) {
			boom = true;
			outSprite.setColor(0.2f, 0.2f, 0.2f, 0f);
		}
	}

	@Override
	public Actor hit(float arg0, float arg1) {
		if (arg0 > ax && arg1 > ay && arg0 < ax + sprite.getWidth() && arg1 < ay + sprite.getHeight()) {
			return this;
		}
		return null;
	}

	@Override
	public boolean touchDown(float x, float y, int pointer) {
		if (boom) {
			Sound sound = BkGlobal.manager.get("dog.mp3", Sound.class);
			sound.play();
			GameScreen.singlePressTime = 0;
			outSprite.setColor(0.2f, 0.2f, 0.2f, 0.8f);
			if (!BkGlobal.ISFINISHED) {
				boom = false;
				for (CatActor actor : BkGlobal.actors) {
					actor.bang();
					actor.clearActions();
					BkGlobal.flyActors.add(actor);
					BkGlobal.getInstance().flayAction(actor);
				}
				BkGlobal.score += BkGlobal.actors.size();
				BkGlobal.actors.clear();
			}
		}
		return true;
	}

	@Override
	public void touchDragged(float x, float y, int pointer) {
		super.touchDragged(x, y, pointer);
	}

	@Override
	public boolean touchMoved(float x, float y) {
		return super.touchMoved(x, y);
	}

	@Override
	public void touchUp(float x, float y, int pointer) {
		if (BkGlobal.ISFINISHED) {
			outSprite.setColor(0.2f, 0.2f, 0.2f, 0f);
		}
		// sprite.setColor(1, 1, 1, 0.1f);
	}

	public void reset() {
		boom = false;
		outSprite.setColor(0.2f, 0.2f, 0.2f, 0.8f);
	}
}
